from PyQt5.QtWidgets import QWidget, QLabel, QApplication, QFileDialog
from PyQt5.QtGui import QMovie
from PyQt5.QtCore import Qt


class pet_Desktop(QWidget):
    def __init__(self):
        super().__init__()
        self.set_win()
        self.pet_main()

    def set_win(self):
        self.resize(336, 297)
        self.setWindowFlags(Qt.WindowType.FramelessWindowHint |
                            Qt.WindowType.WindowStaysOnTopHint)
        self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground, True)

    def pet_main(self):
        pet_lab = QLabel(self)
        pet_gif = QMovie(
            r"images\胡桃抬棺.gif")
        pet_lab.adjustSize()
        pet_lab.resize(320, 125)
        pet_lab.setMovie(pet_gif)
        pet_gif.start()

    def mousePressEvent(self, evt) -> None:
        if evt.button() == Qt.MouseButton.LeftButton:
            self.flag = True
            self.globalX = evt.globalX()
            self.globalY = evt.globalY()

            self.windowGlobalX = self.x()
            self.windowGlobalY = self.y()

    def mouseMoveEvent(self, evt):
        if self.flag:
            move_x = evt.globalX()-self.globalX
            move_y = evt.globalY()-self.globalY
            dest_x = self.windowGlobalX + move_x
            dest_y = self.windowGlobalY + move_y
            self.move(dest_x, dest_y)

    def mouseReleaseEvent(self, evt) -> None:
        self.flag = False

    def fileDialog(self):
        _file = QFileDialog.getOpenFileName(
            self, "open", "E:\images\新建文件夹/", "*.gif")
        print(_file)















































































if __name__ == "__main__":
    app = QApplication([])
    win = pet_Desktop()
    win.show()
    app.exec_()
